<template>
  <view class="container">
    <scroll-view 
      class="scroll-container" 
      scroll-y 
      :show-scrollbar="false"
    >
      <!-- 顶部标题区 -->
      <view class="title-section">
        <text class="main-title">织梦空间</text>
        <text class="sub-title">DREAM SPACE</text>
        <view class="divider"></view>
      </view>

      <!-- 场景描述 -->
      <view class="scene-section">
        <text class="scene-text">在这里，我们打破常规，创造无限可能。每一张照片都是一个故事，每一个场景都是一次冒险。让我们用镜头编织梦想，用光影创造奇迹。</text>
      </view>

      <!-- 照片展示区 -->
      <view class="gallery-section">
        <view v-if="galleryList.length === 0" class="empty-container">
          <text class="empty-text">暂无图片</text>
        </view>
        <view v-else class="gallery-grid">
          <view 
            class="gallery-item" 
            v-for="(item, index) in galleryList" 
            :key="index"
            :class="getGalleryItemClass(item)"
          >
            <image 
              :src="item.image" 
              mode="aspectFill" 
              @error="handleImageError"
            />
            <view class="item-info">
              <text class="item-title">{{ item.title }}</text>
              <text class="item-desc">{{ item.description }}</text>
            </view>
          </view>
        </view>
      </view>
      <van-back-top  bottom="20vh" />
    </scroll-view>
  </view>
</template>

<script setup>
import { ref, onMounted } from "vue";
import { fetchDreamSpaceImages } from '@/services/imageService';

const galleryList = ref([]);

// 处理图片加载错误
const handleImageError = (e) => {
  console.error('Image load error:', e);
  if (e.target) {
    e.target.src = 'https://img01.yzcdn.cn/vant/apple-1.jpg';
  }
};

const getGalleryItemClass = (item) => {
    return {
        'large': item.large
    };
};

onMounted(async () => {
  try {
    galleryList.value = await fetchDreamSpaceImages();
  } catch (error) {
    console.error('Failed to initialize:', error);
    uni.showToast({
      title: '加载失败，请重试',
      icon: 'error'
    });
  }
});
</script>

<style lang="scss">
page {
  height: 100%;
  background-color: #000000;
}

.container {
  height: 100%;
  width: 100%;
}

.scroll-container {
  height: 100%;
  width: 100%;
  padding: 0 24px;
  box-sizing: border-box;
}

.title-section {
  padding: 40px 0 30px;
  text-align: center;
  
  .main-title {
    font-size: 48px;
    font-weight: bold;
    color: #ffffff;
    display: block;
    margin-bottom: 10px;
    letter-spacing: 8px;
    font-family: 'STKaiti', '楷体', serif;
    text-shadow: 0 2px 10px rgba(255, 255, 255, 0.3);
    background: linear-gradient(45deg, #ffffff, #e0e0e0);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    position: relative;
    
    &::after {
      content: '';
      position: absolute;
      bottom: -8px;
      left: 50%;
      transform: translateX(-50%);
      width: 40%;
      height: 2px;
      background: linear-gradient(to right, transparent, rgba(255,255,255,0.8), transparent);
    }
  }
  
  .sub-title {
    font-size: 18px;
    color: rgba(255,255,255,0.8);
    display: block;
    margin-bottom: 16px;
    letter-spacing: 2px;
  }
  
  .divider {
    width: 50px;
    height: 2px;
    background: linear-gradient(to right, transparent, #ffffff, transparent);
    margin: 0 auto;
  }
}

.scene-section {
  padding: 30px 0;
  
  .scene-text {
    font-size: 15px;
    line-height: 1.8;
    color: rgba(255,255,255,0.9);
    text-align: center;
    letter-spacing: 1px;
  }
}

.gallery-section {
  padding-bottom: 30px;
  
  .gallery-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
  }
  
  .gallery-item {
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    
    &.large {
      grid-column: span 2;
      
      image {
        height: 300px;
      }
    }
    
    image {
      width: 100%;
      height: 200px;
      object-fit: cover;
      transition: transform 0.3s ease;
      
      &:hover {
        transform: scale(1.05);
      }
    }
    
    .item-info {
      position: absolute;
      bottom: 0;
      left: 0;
      right: 0;
      padding: 20px;
      background: linear-gradient(to top, rgba(0,0,0,0.9), transparent);
      
      .item-title {
        font-size: 18px;
        color: #ffffff;
        display: block;
        margin-bottom: 6px;
        font-weight: bold;
      }
      
      .item-desc {
        font-size: 14px;
        color: rgba(255,255,255,0.8);
        display: block;
        line-height: 1.4;
      }
    }
  }
}

.empty-container {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
}

.empty-text {
  font-size: 16px;
  color: #ffffff;
  opacity: 0.8;
}
</style> 